package com.imooc.ecommerce.fallback_handler;

import com.alibaba.fastjson.JSON;
import com.imooc.ecommerce.vo.JwtToken;
import com.imooc.ecommerce.vo.UsernameAndPassword;
import lombok.extern.slf4j.Slf4j;

/**
 * Sentinel 回退降级的兜底策略
 * 都需要是静态方法
 * @author zhangshao
 * @since 2023/12/6 23:38
 */
@Slf4j
public class CustomFallbackHandler {

    /**
     * getTokenFromAuthorityServiceFallback方法的fallback
     * @param usernameAndPassword
     * @return
     */
    public static JwtToken getTokenFromAuthorityServiceFallback(UsernameAndPassword usernameAndPassword){
        log.error("get token from authority service fallback: [{}]", JSON.toJSONString("imooc-qinyi-fallback"));
        return new JwtToken("imooc-qinyi-fallback");
    }

    /**
     * ignoreException 的fallback
     * @param code
     * @return
     */
    public static JwtToken ignoreExceptionFallback(Integer code){
        log.error("ignore exception input code :[{}] has trigger exception",code);
        return new JwtToken("imooc-qinyi-fallback");
    }

}
